#include "type.h"

Entier::Entier(QString s ){
    if(s.contains("$") && !s.contains("$0"))
        throw(QString("Complexe inconvertible en Entier"));
    else if(s.contains(".") && !s.contains(".0"))
        throw(QString("Reelle inconvertible en Entier"));
    else if(s.contains("/0"))
        throw(QString("Div /0"));
    else
        val = s;
}

Rationnelle::Rationnelle(QString s){
    if(s.contains("$"))
        throw(QString("Complexe inconvertible en Rationnelle"));
    else if(s.contains("."))
        throw(QString("Reelle inconvertible en Rationnelle"));
    else if(s.contains("/0"))
        throw(QString("Div /0"));
    else
        val = s;
     if(!s.contains("/" ))
        val +="/1";
}

Reelle::Reelle(QString s ){
    if(s.contains("$"))
        throw(QString("Complexe inconvertible en Reelle"));
    else if(s.contains("/" ))
        val = Reelle(Rationnelle(s)).GetQStr();
    else if(!s.contains(".")){
        s += ".0";
        val = s;
    }
    else
        val = s;
}

Complexe::Complexe(QString s ){
    if(s.contains("$"))
        val = s;
    else
        s+="$0";
    val = s;

}

std::complex<double> Complexe::GetValue()const{
    double re, im;

        im = Reelle(this->GetIm()).GetRee();


    re=Reelle(this->GetRe()).GetRee();

    return std::complex<double>(re,im);
}

Reelle::Reelle(const Rationnelle& r){
    std::ostringstream oss;
    double d = (double)r.GetNum()/r.GetDen();
    oss << d;
    val = QString (oss.str().c_str());
}

Reelle::Reelle(double  d){
    std::ostringstream oss;
    oss << d;
    val = QString (oss.str().c_str());
}

Rationnelle::Rationnelle(int a, int b){
    val = QString::number(a);
    val +="/";
    val +=QString::number(b);
}



/*
Complexe::Complexe(const Rationnelle &r){
    QString s = r.GetQStr() += '$0';
    val = s;
}

Complexe::Complexe(const Reelle &r){
    QString s = r.GetQStr() += '$0';
    val = s;
}
*/
